package proxy

import (
	"errors"
)

type tMockOrderService struct {
	mItems map[int]*Order
}

func NewMockOrderService() IOrderService {
	return &tMockOrderService{
		mItems: make(map[int]*Order, 16),
	}
}

func (me *tMockOrderService) Load(id int) (error, *Order) {
	//fmt.Printf("tMockOrderService.Load, id=%v\n", id)
	it, ok := me.mItems[id]
	if ok {
		return nil, it
	} else {
		return errors.New("no such order"), nil
	}
}


func (me *tMockOrderService) Save(it *Order, user IUser) error {
	me.mItems[it.ID] = it
	return nil
}

func (me *tMockOrderService) Delete(id int, user IUser) error {
	_,ok := me.mItems[id]
	if ok {
		delete(me.mItems, id)
	} else {
		return errors.New("no such order")
	}

	return nil
}

